const express = require('express')
const router = express.Router()
const user = require('./api/user')
const employee = require('./api/employee')
const build = require('./api/build')
const fee = require('./api/fee')
const complaints = require('./api/complaints')
const repair = require('./api/repair')
const fitment = require('./api/fitment')
const access = require('./api/access')
const baiduAI = require('./api/baiduAI')
const role = require('./api/role')
const active = require('./api/active')
const carManagement = require('./api/carManagement')
const waterElectricity = require('./api/waterElectricity')
const { authenticateJWT } = require('./jwtAuth')
const multer = require('multer');
const path = require('path');
// 设置文件存储位置和文件名
const storage = multer.diskStorage({
  destination: (req, file, cb) => {
    // 设置文件存储路径
    cb(null, './src/server/uploads');  // 文件将上传到 'uploads' 文件夹
  },
  filename: (req, file, cb) => {
    // 设置文件名，使用当前时间戳防止重名
    cb(null, Date.now() + path.extname(file.originalname));  // 保留文件扩展名
  }
});
// 初始化 multer，限制上传文件大小
const upload = multer({
  storage: storage,
  limits: { fileSize: 5 * 1024 * 1024 }  // 限制文件大小为 5MB
});
//登录
router.post('/login', employee.login)
//用户相关，get方法
router.get('/user/all', authenticateJWT, user.all)
//住户确认
router.get('/user/confirm', authenticateJWT, user.confirm)
//住户确认的审核状态
router.post('/user/confirmEdit', authenticateJWT, user.confirmEdit)
//启用停用
router.post('/user/state', authenticateJWT, user.updateStatus)
//更新所有数据
router.post('/user/allUpdate', authenticateJWT, user.updateAll)
//工作人员
router.get('/employee/all', authenticateJWT, employee.all)
//修改员工的状态
router.post('/employee/edit', authenticateJWT, employee.update)
//修改员工的具体数据
router.post('/employee/AllEdit', authenticateJWT, employee.AllUpdate)
//添加员工
router.post('/employee/add', authenticateJWT, employee.add)
//导入员工
router.post('/employee/importData', authenticateJWT, employee.importData)

//查询某位员工的信息
router.post('/employee/someEmolyee', authenticateJWT, employee.someEmolyee)
//通过手机号修改密码
router.post('/employee/forgetPwd', employee.forgetPwd)
//获取验证码
router.post('/employee/getCode', employee.getCode)
//获取验证码登录用户
router.post('/employee/codeLogin', employee.codeLogin)

//楼表盘
router.get('/build/all', authenticateJWT, build.buildall)
//楼表盘房屋数量
router.get('/build/buildCount', authenticateJWT, build.buildCount)
//楼表盘入住数量
router.get('/build/inRoom', authenticateJWT, build.roomCount)

//缴费相关
router.get('/fee/all', authenticateJWT, fee.employeeFee)
router.get('/fee/allPrice', fee.allPrice)

//投诉建议相关
router.get('/complaints/all', authenticateJWT, complaints.all)
// 修改处理状态
router.post('/complaints/updateState', authenticateJWT, complaints.updateState)

//维修处理相关
router.get('/repair/all', authenticateJWT, repair.all)
// 修改处理状态
router.post('/repair/updateState', authenticateJWT, repair.updateState)
//装修相关
router.get('/fitment/all', authenticateJWT, fitment.all)
//修改审批状态
router.post('/fitment/updateState', authenticateJWT, fitment.updateState)
// 收取服务费
router.post('/fitment/replayFree', authenticateJWT, fitment.replayFree)
//验收
router.post('/fitment/acceptance', authenticateJWT, fitment.acceptance)



//出入管理
router.get('/access/entryExit', authenticateJWT, access.entryExit)
//访客管理
router.get('/access/allVisitor', authenticateJWT, access.visitor)
//图片上传
router.post('/access/updated', upload.single('file'), access.updated)
//添加访客
router.post('/access/addVisitor', authenticateJWT, access.addVisitor)
//门禁权限
router.get('/access/permissions', authenticateJWT, access.permissions)
//修改门禁权限
router.post('/access/updatePermissions', authenticateJWT, access.updatePermissions)

//人脸对比
router.post('/access/faceRecognition', authenticateJWT, baiduAI.faceRecognition)
//修改卡片状态
router.post('/access/updateCardState', authenticateJWT, access.updateCardState)
//新增卡片状态
router.post('/access/insertCard', authenticateJWT, access.insertCard)
//查询所有的门禁设备
router.get('/access/allEquipment', authenticateJWT, access.allEquipment)
//新增门禁设备
router.post('/access/addEquipment', authenticateJWT, access.addEquipment)
//修改门禁设备
router.post('/access/editEquipment', authenticateJWT, access.editEquipment)
//批量设置密码
router.post('/access/allPassword', authenticateJWT, access.allPassword)
//角色管理
router.get('/role/allRole', authenticateJWT, role.allRole)
//修改数据
router.post('/role/editRole', authenticateJWT, role.editRole)
//更新状态
router.post('/role/updateRoleState', authenticateJWT, role.updateRoleState)
//新增权限
router.post('/role/insertRole', authenticateJWT, role.insertRole)
//查询某个权限
router.post('/role/someRole', authenticateJWT, role.someRole)

//内容管理
//社区活动
router.get('/active/all', authenticateJWT, active.all)
// 修改报名状态
router.post('/active/updateEnrollState', authenticateJWT, active.updateEnrollState)
//新增活动
router.post('/active/addActive', authenticateJWT, active.addActive)
//修改审核状态
router.post('/active/updateAuditState', authenticateJWT, active.updateAuditState)
//修改活动状态
router.post('/active/updateActiveState', authenticateJWT, active.updateActiveState)



//社区公告
router.get('/active/announcement', authenticateJWT, active.announcement)
//更新公告
router.post('/active/updateAnnouncement', authenticateJWT, active.updateAnnouncement)
//新增公告
router.post('/active/insertAnnouncement', authenticateJWT, active.insertAnnouncement)

//小区民警
router.get('/active/communitypolice', authenticateJWT, active.communitypolice)
//修改民警信息
router.post('/active/editPoliceInfo', authenticateJWT, active.editPoliceInfo)

//便民电话
router.get('/active/convenient', authenticateJWT, active.convenient)
//修改便民电话
router.post('/active/updateConvenient', authenticateJWT, active.updateConvenient)

// 车辆管理
router.get('/carManagement/allCar', authenticateJWT, carManagement.allCar)
//修改车辆数据
router.post('/carManagement/updateCar', authenticateJWT, carManagement.updateCar)


//水电气管理
router.get('/waterElectricity/allWaterMeter', authenticateJWT, waterElectricity.allWaterMeter)
//修改水表告警数据
router.post('/waterElectricity/updateWaterMeter', authenticateJWT, waterElectricity.updateWaterMeter)
//水表充值记录查询
router.get('/waterElectricity/waterRecharge', authenticateJWT, waterElectricity.waterRecharge)

module.exports = router